var o = require("../../../components/shopping_cart/shopping_cart.js"), t = require("../../../components/specifications_model/specifications_model.js");

Page({
    data: {
        quick_list: [],
        goods_list: [],
        carGoods: [],
        currentGood: {},
        checked_attr: [],
        checkedGood: [],
        attr_group_list: [],
        temporaryGood: {
            price: 0,
            num: 0,
            use_attr: 1
        },
        check_goods_price: 0,
        showModal: !1,
        checked: !1,
        cat_checked: !1,
        color: "",
        total: {
            total_price: 0,
            total_num: 0
        }
    },
    onLoad: function(o) {
        getApp().page.onLoad(this, o);
    },
    onShow: function() {
        getApp().page.onShow(this), o.init(this), t.init(this, o), this.loadData();
    },
    onHide: function() {
        getApp().page.onHide(this), o.saveItemData(this);
    },
    onUnload: function() {
        getApp().page.onUnload(this), o.saveItemData(this);
    },
    loadData: function(o) {
        var t = this, e = getApp().core.getStorageSync(getApp().const.ITEM), a = {
            total_num: 0,
            total_price: 0
        };
        t.setData({
            total: void 0 !== e.total ? e.total : a,
            carGoods: void 0 !== e.carGoods ? e.carGoods : []
        }), getApp().core.showLoading({
            title: "加载中"
        }), getApp().request({
            url: getApp().api.quick.quick,
            success: function(o) {
                if (getApp().core.hideLoading(), 0 == o.code) {
                    var a = o.data.list, s = [], i = [], c = [];
                    for (var d in a) if (a[d].goods.length > 0) {
                        i.push(a[d]);
                        for (var n in a[d].goods) {
                            var r = !0;
                            if (getApp().helper.inArray(a[d].goods[n].id, c) && (a[d].goods.splice(n, 1), r = !1), 
                            r) {
                                var p = t.data.carGoods;
                                for (var g in p) e.carGoods[g].goods_id === parseInt(a[d].goods[n].id) && (a[d].goods[n].num = a[d].goods[n].num ? a[d].goods[n].num : 0, 
                                a[d].goods[n].num += e.carGoods[g].num);
                                if (parseInt(a[d].goods[n].hot_cakes)) {
                                    var u = !0;
                                    for (var h in s) s[h].id == a[d].goods[n].id && (u = !1);
                                    u && s.push(a[d].goods[n]);
                                }
                                c.push(a[d].goods[n].id);
                            }
                        }
                    }
                    console.log(i), t.setData({
                        quick_hot_goods_lists: s,
                        quick_list: i
                    });
                }
            }
        });
    },
    get_goods_info: function(o) {
        var t = this, e = t.data.carGoods, a = t.data.total, s = t.data.quick_hot_goods_lists, i = t.data.quick_list, c = {
            carGoods: e,
            total: a,
            quick_hot_goods_lists: s,
            check_num: t.data.check_num,
            quick_list: i
        };
        getApp().core.setStorageSync(getApp().const.ITEM, c);
        var d = o.currentTarget.dataset.id;
        getApp().core.navigateTo({
            url: "/pages/goods/goods?id=" + d + "&quick=1"
        });
    },
    selectMenu: function(o) {
        var t = o.currentTarget.dataset, e = this.data.quick_list;
        if ("hot_cakes" == t.tag) for (var a = !0, s = e.length, i = 0; i < s; i++) e[i].cat_checked = !1; else {
            for (var c = t.index, s = e.length, i = 0; i < s; i++) e[i].cat_checked = !1, e[i].id == e[c].id && (e[i].cat_checked = !0);
            a = !1;
        }
        this.setData({
            toView: t.tag,
            quick_list: e,
            cat_checked: a
        });
    },
    onShareAppMessage: function(o) {
        getApp().page.onShareAppMessage(this);
        var t = this;
        return {
            path: "/pages/quick-purchase/index/index?user_id=" + getApp().core.getStorageSync(getApp().const.USER_INFO).id,
            success: function(o) {
                1 == ++share_count && t.shareSendCoupon(t);
            }
        };
    },
    close_box: function(o) {
        this.setData({
            showModal: !1
        });
    },
    hideModal: function() {
        this.setData({
            showModal: !1
        });
    }
});